﻿@namespace Masa.Blazor.Presets.PageStack
@using StyleBuilder = Masa.Blazor.Core.StyleBuilder
@inherits MasaComponentBase

<MDialog Transition="dialog-right-transition"
         Value="@Active"
         ContentClass="@GetClass()"
         ContentStyle="@GetStyle()"
         Fullscreen
         Persistent
         NoPersistentAnimation
         ContentAttributes="@(new Dictionary<string, object> { { "page-stack-id", Index } })">
    <MShouldRender Value="@CanRender">
        <CascadingValue Value="this" IsFixed>
            <MAppBar Class="@GetClass(_block.Element("bar").Name, AppBarClass)"
                     Style="@AppBarStyle"
                     Color="@AppBarColor"
                     Dense="@AppBarDense"
                     Short="@AppBarShort"
                     ElevateOnScroll="@ElevateOnScroll"
                     ExtensionContent="@ExtensionContent"
                     ExtensionHeight="@ExtensionHeight"
                     Fixed
                     Flat="@AppBarFlat"
                     Height="@(AppBarHeight == 0 ? null : AppBarHeight)"
                     ImgContent="@ImageContent"
                     ShrinkOnScroll="@ShrinkOnScroll"
                     Src="@AppBarImage"
                     ScrollTarget="@($"[page-stack-id=\"{Index}\"]>.m-dialog")"
                     Light="@AppBarLight"
                     Dark="@AppBarDark">
                <ChildContent>
                    @if (AppBarContent is not null)
                    {
                        @AppBarContent.Invoke(new PageStackGoBackContext(HandleOnGoBack))
                    }
                    else
                    {
                        @if (GoBackContent is not null)
                        {
                            @GoBackContent.Invoke(new PageStackGoBackContext(HandleOnGoBack))
                        }
                        else
                        {
                            <MButton Icon OnClick="@OnGoBack">
                                <MIcon>$goBack</MIcon>
                            </MButton>
                        }

                        <MAppBarTitle>
                            @AppBarTitle
                        </MAppBarTitle>
                        
                        <MSpacer />

                        <div class="@_block.Element("actions")">
                            @ActionContent
                        </div>
                    }
                </ChildContent>
            </MAppBar>
            <div class="@_block.Element("content")"
                 style="@StyleBuilder.Create().Add("padding-top", $"{ComputedBarHeight}px")">
                @ChildContent
            </div>
        </CascadingValue>
    </MShouldRender>
</MDialog>